import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
 
const store = new Vuex.Store({
  state: {
    // 存储token
    Authorization: localStorage.getItem('Authorization') ? localStorage.getItem('Authorization') : '',
	user_name: '' || localStorage.getItem('user_name'),
  display_userame: '' || localStorage.getItem('display_userame'),
	UserId: '' || localStorage.getItem('UserId'),
	RoleId: '' || localStorage.getItem('RoleId'),   
	cityId: '' || localStorage.getItem('cityId'),      
	user_manager: '' || localStorage.getItem('user_manager'),
	search_phone: '' || localStorage.getItem('search_phone'),
  user_limit: '' || localStorage.getItem('user_limit'),
  regionType: '' || localStorage.getItem('regionType'),
  map: '' || localStorage.getItem('map'),
  days: '' || localStorage.getItem('days'),
  cbStoreInfo: '' || localStorage.getItem('cbStoreInfo'),
  cbUserInfo: '' || localStorage.getItem('cbUserInfo'),
  cbUserId: '' || localStorage.getItem('cbUserId'),
  cbToken: '' || localStorage.getItem('cbToken'),
  cbStoreId: '' || localStorage.getItem('cbStoreId'),
  cbUserPhone: '' || localStorage.getItem('cbUserPhone'),
  
  },
 
  mutations: {
    // 修改token，并将token存入localStorage
    changeLogin (state, user) {
     state.Authorization = user.Authorization;
     localStorage.setItem('Authorization', user.Authorization);
    },
	handleUserName: (state, user_name) => {
	        state.user_name = user_name
	         // 把登录的用户名保存到localStorage中，防止页面刷新，导致vuex重新启动，用户名就成为初始值（初始值为空）的情况
	        localStorage.setItem('user_name', user_name)
	    },
      handleDisPlayUserName: (state, display_userame) => {
        state.display_userame = display_userame
         // 把登录的用户名保存到localStorage中，防止页面刷新，导致vuex重新启动，用户名就成为初始值（初始值为空）的情况
        localStorage.setItem('display_userame', display_userame)
    },
	handleUserId: (state, UserId) => {
	        state.UserId = UserId
	        // 把登录的用户ID保存到localStorage中  manager.id
	        localStorage.setItem('UserId', UserId)
			},

	handleRoleId: (state, RoleId) => {
		state.RoleId = RoleId
		 //新增 body.id  
		localStorage.setItem('RoleId', RoleId)
		},

		handlecityId: (state, cityId) => {
			state.cityId = cityId
			  
			localStorage.setItem('cityId', cityId)
			},

	handlemanager: (state, user_manager) => {
	        state.user_manager = user_manager
	        localStorage.setItem('user_manager', user_manager)
	    },
    handleUserLimit: (state, user_limit) => {
      state.user_limit = user_limit
      localStorage.setItem('user_limit', user_limit)
  },
  handleCbStoreInfo: (state, cbStoreInfo) => {
	state.cbStoreInfo = cbStoreInfo
	localStorage.setItem('cbStoreInfo', cbStoreInfo)
},
handleCbUserInfo: (state, cbUserInfo) => {
	state.cbUserInfo = cbUserInfo
	localStorage.setItem('cbUserInfo', cbUserInfo)
},
setCbUserId: (state, cbUserId) => {
	state.cbUserId = cbUserId
	localStorage.setItem('cbUserId', cbUserId)
},
setCbUserPhone: (state, cbUserPhone) => {
	state.cbUserPhone = cbUserPhone
	localStorage.setItem('cbUserPhone', cbUserPhone)
},

setCbToken: (state, cbToken) => {
	state.cbToken = cbToken
	localStorage.setItem('cbToken', cbToken)
},
setCbStoreId: (state, cbStoreId) => {
	state.cbStoreId = cbStoreId
	localStorage.setItem('cbStoreId', cbStoreId)
},

  handleRegionType: (state, regionType) => {
	state.regionType = regionType
	localStorage.setItem('regionType', regionType)
},
Map: (state, map) => {
	state.map = map
	localStorage.setItem('map', map)
},
	handlesearchPhone: (state, search_phone) => {
			state.search_phone = search_phone
			 // 把登录的用户名保存到localStorage中，防止页面刷新，导致vuex重新启动，用户名就成为初始值（初始值为空）的情况
			localStorage.setItem('search_phone', search_phone)
		},
		days: (state, days) => {
			state.days = days
			localStorage.setItem('days', days)
		},
  },
	getters:{
		userName: (state) => state.user_name,
    displayUserame: (state) => state.display_userame,
		Authorization: (state) => state.Authorization,
		UserId:(state) => state.UserId,
		RoleId:(state) => state.RoleId,   
		cityId:(state) => state.cityId, 
		usermanager: (state) => state.user_manager,
       userLimit: (state) => state.user_limit,
	   cbStoreInfo: (state) => state.cbStoreInfo,
	   cbUserInfo: (state) => state.cbUserInfo,

	   cbUserPhone: (state) => state.cbUserPhone,
	   cbUserId: (state) => state.cbUserId,
	   cbToken: (state) => state.cbToken,
	   cbStoreId: (state) => state.cbStoreId,
		search_phone: (state) => state.search_phone,
		regionType: (state) => state.regionType,
    	map: (state) => state.map,
		days:(state) => state.days,
	}
});
 
export default store;